package com.vast.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vast.admin.api.CietacApi;
import com.vast.admin.api.cietac.entity.*;
import com.vast.admin.entity.ArbitrationCase;
import com.vast.admin.entity.ArbitrationProject;
import com.vast.admin.service.ArbitrationCaseService;
import com.vast.admin.service.IArbitrationProjectService;
import com.vast.common.constant.MessageCode;
import com.vast.common.core.domain.Result;
import com.vast.common.core.domain.entity.SysUser;
import com.vast.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(value = "仲裁项目控制器", tags = {"仲裁项目管理"})
@RestController
@RequestMapping("/manager/arbitration/case")
public class ArbitrationCaseController {

    @Autowired
    private ArbitrationCaseService arbitrationCaseService;

    @Autowired
    private IArbitrationProjectService arbitrationProjectService;

	@Autowired
	private CietacApi cietacApi;


	/**
     * 分页查询
     * @param arbitrationCase
     * @param page
     * @return
     */
    @ApiOperation("分页查询")
    @GetMapping("/page")
    public com.vast.common.core.domain.Result<IPage<ArbitrationCase>> page(ArbitrationCase arbitrationCase, Page<ArbitrationCase> page) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        return new Result<>(MessageCode.SUCCESS, arbitrationCaseService.page(page, arbitrationCase, manager));
    }

    /**
     * 获取项目
     * @return
     */
    @ApiOperation("获取项目")
    @GetMapping("/getProject")
    public Result<List<ArbitrationProject>> getProject() {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
        return new Result<>(MessageCode.SUCCESS, arbitrationProjectService.getList(manager));
    }

    @ApiOperation("保存案件信息")
    @PostMapping("/saveArbitrationCase")
	public Result<CietacLawcaseId> saveArbitrationCase(@RequestParam("arbitrationCase") String arbitrationCase, @RequestParam("files") MultipartFile[] files) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
    	return arbitrationCaseService.saveArbitrationCase(arbitrationCase, files, manager);
	}

	@ApiOperation("获取案件附件上传说明")
	@GetMapping("/getProjectTypeRemark")
	public Result<ProjectTypeRemark> getProjectTypeRemark(Long projectId) {
		return cietacApi.getProjectTypeRemark(projectId);
	}

	@ApiOperation("获取地区编码")
	@GetMapping("/getBaseRegion")
	public Result<List<BaseRegion>> getBaseRegion() {
		return cietacApi.getBaseRegion();
	}

	@ApiOperation("获取案件详情")
	@GetMapping("/getCaseInfo")
	public Result<CaseInfo> getCaseInfo(Long caseId) {
    	SysUser manager = SecurityUtils.getLoginUser().getUser();
		return cietacApi.getCaseInfo(manager.getMobile(), caseId);
	}

	@ApiOperation("案件费用支付")
	@GetMapping("/pay")
	public Result<PayResponse> pay(Long caseId) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
		return cietacApi.pay(manager.getMobile(), caseId);
	}

	@ApiOperation("文书管理")
	@GetMapping("/caseDocument")
	public Result<PageResponse<CaseDocument>> caseDocument(@RequestParam("id") Long id, @RequestParam("page") int page, @RequestParam("size")int size) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
    	return cietacApi.caseDocument(manager.getMobile(), id, page, size);
	}

	@ApiOperation("文件管理")
	@GetMapping("/caseFile")
	public Result<List<CaseFileResponse>> caseFile(@RequestParam("id") Long id) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
		return cietacApi.caseFile(manager.getMobile(), id);
	}

	@ApiOperation("补件通知")
	@GetMapping("/caseNotice")
	public Result<List<CaseNoticeResponse>> caseNotice(@RequestParam("id") Long id) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
		return cietacApi.caseNotice(manager.getMobile(), id);
	}

	@ApiOperation("补件申请")
	@PostMapping("/confirmCaseFile")
	public Result<Void> confirmCaseFile(@RequestParam("id") Long id, @RequestParam("filename") String filename, @RequestParam("userComplain") String userComplain, @RequestParam("userComplainFile") MultipartFile userComplainFile) {
		SysUser manager = SecurityUtils.getLoginUser().getUser();
    	return cietacApi.confirmCaseFile(manager.getMobile(), id, filename, userComplain, userComplainFile);
	}


}
